#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    float n,d[10],least,x[10],y[10],ya[10],yb[10];
    float yellow,err,errr,yy,A,B,C,y0,d0,left[10],right[10],l[10],r[10];
    int m,h,i;
    cout<<"\nEnter the number of prominent lines:\t";
    cin>>m;
    cout<<"\nEnter the telescope readings\n";
    for(i=1;i<=m;i++)
    {
        cin>>x[i];
    }
    least=x[1];
    for(i=1;i<=m;i++)
    {
        d[i]=(x[i]-least)/100;
    }
    cout<<"\nEnter the wavelengths\n";
    for(i=1;i<=m;i++)
    {
        cin>>ya[i];
    }
    for(i=1;i<=m;i++)
    {
        y[i]=ya[i]/1000000000;
    }
    A=(d[2]-d[1])/(y[2]-y[1]);
    B=(d[3]-d[1])/(y[3]-y[1]);
    y0=y[1]-((d[3]-d[2])/(A-B));
    d0=A*(y[2]-y0)+d[1];
    C=(d0-d[1])*(d[3]-d[2])/(A-B);
    yy=y0+C/(d0-d[4]);
    cout<<"\nEnter the number of bands:\t";
    cin>>n;
    cout<<"\nEnter left and right readings of bands\n";
    for(i=1;i<=n;i++)
    {
        cin>>left[i];
        cin>>right[i];
        cout<<"\n";
    }
    for(i=1;i<=n;i++)
    {
        l[i]=(left[i]-least)/100;
        r[i]=(right[i]-least)/100;
    }
    for(i=1;i<=n;i++)
    {
        ya[i]=y0+C/(d0-l[i]);
        yb[i]=y0+C/(d0-r[i]);
    }
    for(i=1;i<=n;i++)
    {
        cout<<"\nFor "<<i<<"th band"<<"\t";
        cout<<endl;
        cout<<ya[i]<<"\t";
        cout<<yb[i];
        cout<<"\n";
    }
    cout<<"\nThe bandwidth of the bands are \n";
    for(i=1;i<=n;i++)
    {
        cout<<ya[i]-yb[i]<<endl;
    }
    err=fabs((yy-y[4])*100);
    cout<<err<<"\n"<<y[4];
    errr=err/y[4];
    cout<<"\nWavelength of yellow\t"<<yy<<" with\t"<<errr<<"% error\n";
    cout<<"\nHartmann's constants are\n";
    cout<<"\nS0\t"<<d0;
    cout<<"\nd0\t"<<y0;
    cout<<"\nC\t"<<C;
    cin.get();
}
